package com.huluobo.a2303mdmdemo.goods

import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.StateType
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/9/3.
 */
@HiltViewModel
class GoodsViewModel @Inject constructor(private val goodsRepo: GoodsRepo) : BaseViewModel<GoodsIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is GoodsIntent.GetAllGoods -> {
                httpRequest(goodsRepo.getAllGoods(it.categoryId, it.currentPage, it.pageSize) as Flow<Res<Any>>)
            }

            is GoodsIntent.AddToCart -> {
                httpRequest(goodsRepo.addToCart(it.map), StateType.ADD_TO_CART)
            }

            is GoodsIntent.GetAllCart -> {
                httpRequest(goodsRepo.getCart() as Flow<Res<Any>>)
            }
        }
    }
}